package com.itbaizhan.controller;

import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.ollama.OllamaChatModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ChatController {

    private final OllamaChatModel chatModel;

    @Autowired
    public ChatController(OllamaChatModel chatModel) {
        this.chatModel = chatModel;
    }

    /**
     * ai聊天
     * @param message
     * @return
     */
    @GetMapping("/chat")
    public String chat(String message){
        ChatResponse call = chatModel.call(new Prompt(message));
        return call.getResult().getOutput().getContent();

    }


}
